package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {
    //查询当前购物车的DishId或SetmealId的信息
    ShoppingCart findByShoppingCart(ShoppingCart shoppingCart);
    //更新购物车菜品或套餐数量
    @Update("update Shopping_cart set number=#{number} where id=#{id}")
    Integer update(@Param("id") Long id, @Param("number") Integer number);
    //保存购物车信息
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId}" +
            ",#{dishFlavor},1,#{amount},#{createTime})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer save(ShoppingCart shoppingCart);
    //查询指定用户的购物车数据
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findAllUserId(Long userId);
    //清空购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    Integer deleteByUserId(Long userId);
}
